#include "myShaderPhong.h"
#include "myLight.h"

myShaderPhong::myShaderPhong()
{
	VSres = new Phong::VSR;
	PSres = new Phong::PSR;
	VS = Phong::VertexShader;
	PS = Phong::PixelShader;
	nSem = Phong::nSem;
	Sem = (InterpSemantic *) (Phong::Sem);
	PSstride = sizeof(Phong::PIXELin);
}

myShaderPhong::~myShaderPhong(){
	delete(Phong::VSR*)VSres;
	delete(Phong::PSR*)PSres;
}

void myShaderPhong::Update(void)
{
		printf("\nUpdate de myShaderPhong\n");
	
		Check();
		camera.Update();
			
			_mat4 matInv;
			_vec3 pos;
			_vec3 tmp;
			int test;
		
			int i = 0;
			int j = 0;

			
			matInv.set(world);
			matInv.inverse(matInv);
			
			((Phong::VSR*)VSres)->MFull.mul(camera.GetProjViewMatrix(),world);

			((Phong::PSR*)PSres)->ObsPos.mul(matInv,camera.GetPosition());
			((Phong::PSR*)PSres)->material = material;

			for(i=0;i<MaxLight;i++){
				if(lights[i].active){
					tmp = lights[i].pos;
					pos.mul(matInv,tmp);
					
					((Phong::PSR*)PSres)->lights[j].pos = pos;
					((Phong::PSR*)PSres)->lights[j].col = lights[i].col;	
					j++;
				}
			}	
			((Phong::PSR*)PSres)->nlights = j;

}